package main.java.com.zzxy.springmvc34.controller;

import main.java.com.zzxy.springmvc34.po.Student;
import main.java.com.zzxy.springmvc34.po.StudentExt;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import static java.io.FileDescriptor.out;


@Controller
@RequestMapping("/stu")
public class StudentController {


    @RequestMapping("register")
    public String register(){return "/user/register";}

    @RequestMapping("insert")
    public @ResponseBody Student insert(@RequestBody Student student){
        //service > dao > jdbctemplate > mysql
        student.setUsername(student.getUsername()+ "123");
        student.setPassword(student.getPassword()+ "abc");
        return student;
    }


    @RequestMapping("addstu")
    public String addStudent(String username, String password, Model model){
        System.out.println(username);
        System.out.println(password);
        model.addAttribute("username", username);
        model.addAttribute("password", password);
        return "/user/userlist";
    }



    @RequestMapping("addstu1")
    public String addStudent1(Student student){
        System.out.println(student);
        return "/user/userlist";
    }


    @RequestMapping("addStu2")
    public String addStudent2(StudentExt ext){
        /*System.out.println(ext.getStudent());
        for(Student student:ext.getStudentList()){
            System.out.println(student);
        }*/
        System.out.println(out);
        return "";
    }
}
